import test.Yewu;
import org.objectweb.asm.*;
import org.objectweb.asm.util.ASMifier;
import org.objectweb.asm.util.TraceClassVisitor;
import org.objectweb.asm.util.TraceMethodVisitor;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;

public class test002 {
    public static void main(String[] args) throws Exception {
        InputStream resource = Yewu.class.getResourceAsStream(Yewu.class.getSimpleName() + ".class");

        byte[] bytes = new byte[resource.available()];
        resource.read(bytes);

        String method = "main";
        String desc = "([Ljava/lang/String;)V";

        int api = Opcodes.ASM9;
        ClassReader cr = new ClassReader(bytes);


        ClassVisitor cv = null;

        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        {
            cv = cw;
        }

        {
            cv = new TraceClassVisitor(cv, new ASMifier(), new PrintWriter(System.out));
        }

        ASMifier printer = new ASMifier();
        {
            MyClassVisitor myClassVisitor = new MyClassVisitor(api, cv);
            myClassVisitor.setDesc(desc);
            myClassVisitor.setMethodName(method);

            myClassVisitor.setMethodVisitor(new TraceMethodVisitor(printer));

//            cv = myClassVisitor;
        }

        cv = new ClassVisitor(api, cv) {
            @Override
            public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
                if (method.equals(name)) {
                    return null;
                }
                return super.visitMethod(access, name, descriptor, signature, exceptions);
            }
        };

        cr.accept(cv, ClassReader.SKIP_FRAMES);


        List<Object> text = printer.text;
        System.out.println("--------");
        text.stream().forEach(System.out::print);



    }
}
